package com.jky.stmall.exercise;

public class quickSort {
    public static void main(String[] args) {
        int[] a={3,5,8,9,1,2,6};
        quick(a,0,a.length-1);
        for (int i =0;i<a.length;i++){
            System.out.println(a[i]);
        }
    }
    public static void quick(int[] a,int left,int right){
        if(left>=right){
            return;
        }
        int l = left;
        int r = right;
        int s=a[left];
        while (l<r){
            while (l<r&&a[r]>=s){
                r--;
            }
            while (l<r&&a[l]<=s){
                l++;
            }
            int t=a[r];
            a[r]=a[l];
            a[l]=t;
        }
        int k = a[r];
        a[r]=a[left];
        a[left]=k;
        quick(a,left,r-1);
        quick(a,r+1,right);

    }
}
